package eerbaar.internal.level;

import eerbaar.context.IContext;
import eerbaar.level.IMessage;
import eerbaar.shared.message.IMessageReader;
import eerbaar.shared.message.MsgHelper;

public class Message extends ActionCollection implements IMessage,
        IMessageReader {

    private IContext model;
    private String name;

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public boolean read(eerbaar.shared.message.Message msg) {
        super.execute(this.model, msg.getMap());
        return false;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void start(IContext model) {
        assert (this.model == null);

        this.model = model;
        MsgHelper.registerReader(this.name, this);
    }

    @Override
    public void stop() {
        assert (this.model != null);

        MsgHelper.unregisterReader(this.name, this);
        this.name = null;
    }

}
